/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package mrez.zBox.hotkey;

import de.ksquared.system.keyboard.GlobalKeyListener;
import de.ksquared.system.keyboard.KeyAdapter;
import de.ksquared.system.keyboard.KeyEvent;
import java.util.logging.Level;
import java.util.logging.Logger;
import mrez.zBox.zaBox;

/**
 *
 * @author Ahmed
 */
public class HotKey {
    public zaBox m_App;
    private KeyAdapter key;
    
    public HotKey( zaBox aApp )
    {
        m_App = aApp;
         
    }
    
    public void AssignHotKey( int key )
    {
        this.key = new KeyAdapter() {            
            @Override
            public void keyPressed(KeyEvent event)
            {
                if(event.getVirtualKeyCode()==KeyEvent.VK_OEM_3 && event.isCtrlPressed() && ! m_App.m_Window.isVisible())
                    m_App.m_Window.setVisible(true);
            }

            
            @Override
            public void keyReleased(KeyEvent event)
            {
                if(m_App.m_Window.isVisible())
                    m_App.m_Window.setVisible(false);
            }
         };
        new GlobalKeyListener().addKeyListener(this.key);
    }
    
    /**
     *
     */
    @Override
    protected void finalize () {
        try {
            super.finalize();
        } catch (Throwable ex) {
            Logger.getLogger(HotKey.class.getName()).log(Level.SEVERE, null, ex);
        }
        new GlobalKeyListener().removeKeyListener(this.key);
    }
}
